public class Solution {
    public String longestCommonPrefix(String[] strs) {
        int slen = strs.length;
        if(slen == 0) {
            return "";
        }

        int minlen = Integer.MAX_VALUE;
        for(String str : strs) {
            if(str.length() < minlen) {
                minlen = str.length();
            }
        }

        StringBuilder comstr = new StringBuilder();
        for(int i = 0; i < minlen; i++) {
            for(String str : strs) {
                if(str.charAt(i) != strs[0].charAt(i)) {
                    return comstr.toString();
                }
            }
            comstr.append(strs[0].charAt(i));
        }
        return comstr.toString();
    }
}